Change in openvpn[master]: unit_tests: prefer proper cmocka assert helpers
A message that is not in the archive (sent off-list or not yet received): gerrit.1762213799000.I61e4968f2e83d12d4d3fc3ccba92a06eb5ed5866@...2715...
Attention is currently required from: flichtenheld, plaisthos.
Hello plaisthos, flichtenheld,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/1345?usp=email
to review the following change.
Change subject: unit_tests: prefer proper cmocka assert helpers
......................................................................
unit_tests: prefer proper cmocka assert helpers
We have agreed to never use the plain assert()
anywhere in the code.
Unit tests are almost there as they always use cmocka provided assert helpers, except for two cases. Convert those two to cmocka assert calls too.
While at it also ensure that the proper bool helpers are used rather than checking _int_equal against true/false.
Drop assert.h in cryptoapi.c as well as it's not needed anymore.
GitHub: Closes OpenVPN/openvpn#894
---
M src/openvpn/cryptoapi.c
M tests/unit_tests/openvpn/test_buffer.c
M tests/unit_tests/openvpn/test_cryptoapi.c
M tests/unit_tests/openvpn/test_misc.c
M tests/unit_tests/openvpn/test_pkcs11.c
5 files changed, 14 insertions(+), 15 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/45/1345/1
src/openvpn/cryptoapi.c +0 -1
@@ -45,7 +45,6 @@#include <ncrypt.h> #include <stdio.h> #include <ctype.h> -#include <assert.h> #include "buffer.h" #include "openssl_compat.h"
tests/unit_tests/openvpn/test_buffer.c +11 -11
@@ -463,38 +463,38 @@const char test1[] =A_TIMES_256 "EOL\n" A_TIMES_256 "EOF" ;/* line buffer bigger than actual line */ -assert_int_equal (buf_write (&buf, test1,sizeof (test1)), true); +assert_true (buf_write (&buf, test1,sizeof (test1))); status =buf_parse (&buf,'\n' , line,sizeof (line)); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,A_TIMES_256 "EOL" ); status =buf_parse (&buf,'\n' , line,sizeof (line)); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,A_TIMES_256 "EOF" );/* line buffer exactly same size as actual line + terminating \0 */ buf_reset_len (&buf); -assert_int_equal (buf_write (&buf, test1,sizeof (test1)), true); +assert_true (buf_write (&buf, test1,sizeof (test1))); status =buf_parse (&buf,'\n' , line,260 ); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,A_TIMES_256 "EOL" ); status =buf_parse (&buf,'\n' , line,260 ); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,A_TIMES_256 "EOF" );/* line buffer smaller than actual line */ buf_reset_len (&buf); -assert_int_equal (buf_write (&buf, test1,sizeof (test1)), true); +assert_true (buf_write (&buf, test1,sizeof (test1))); status =buf_parse (&buf,'\n' , line,257 ); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,A_TIMES_256 ); status =buf_parse (&buf,'\n' , line,257 ); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,"EOL" ); status =buf_parse (&buf,'\n' , line,257 ); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,A_TIMES_256 ); status =buf_parse (&buf,'\n' , line,257 ); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,"EOF" );gc_free (&gc);
tests/unit_tests/openvpn/test_cryptoapi.c +1 -1
@@ -121,7 +121,7 @@ { cert4, key4, cname4, "OVPN TEST CA2", "OVPN Test Cert 4", hash4, 0 }, { 0 } }; -assert (sizeof (certs_local) ==sizeof (certs)); +assert_int_equal (sizeof (certs_local),sizeof (certs));memcpy (certs, certs_local,sizeof (certs_local)); }
tests/unit_tests/openvpn/test_misc.c +1 -1
@@ -101,7 +101,7 @@const char *msg =parse_auth_failed_temp (&o, teststr);assert_string_equal (msg,"" );assert_int_equal (o.server_backoff_time,42 ); -assert_int_equal (o.no_advance, true); +assert_true (o.no_advance); } static void
tests/unit_tests/openvpn/test_pkcs11.c +1 -1
@@ -148,7 +148,7 @@ { cert4, key4, cname4, "OVPN TEST CA2", "OVPN Test Cert 4", { 0 }, NULL }, { 0 } }; -assert (sizeof (certs_local) ==sizeof (certs)); +assert_int_equal (sizeof (certs_local),sizeof (certs));memcpy (certs, certs_local,sizeof (certs_local)); }
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1345?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I61e4968f2e83d12d4d3fc3ccba92a06eb5ed5866
Gerrit-Change-Number: 1345
Gerrit-PatchSet: 1
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Attention is currently required from: flichtenheld, ordex, plaisthos.
cron2 has posted comments on this change by ordex. ( http://gerrit.openvpn.net/c/openvpn/+/1345?usp=email )
Change subject: unit_tests: prefer proper cmocka assert helpers
......................................................................
Patch Set 1: Code-Review+2
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1345?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I61e4968f2e83d12d4d3fc3ccba92a06eb5ed5866
Gerrit-Change-Number: 1345
Gerrit-PatchSet: 1
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Tue, 04 Nov 2025 08:16:25 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
PATCH 1/1 unit_tests: prefer proper cmocka assert helpers
In reply to a message not in the archiveFrom: Antonio Quartulli <[email protected]...>
We have agreed to never use the plain assert()
anywhere in the code.
Unit tests are almost there as they always use cmocka provided assert helpers, except for two cases. Convert those two to cmocka assert calls too.
While at it also ensure that the proper bool helpers are used rather than checking _int_equal against true/false.
Drop assert.h in cryptoapi.c as well as it's not needed anymore.
GitHub: Closes OpenVPN/openvpn#894
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1345
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1345
This mail reflects revision 1 of this Change.
Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>
src/openvpn/cryptoapi.c +0 -1
@@ -45,7 +45,6 @@#include <ncrypt.h> #include <stdio.h> #include <ctype.h> -#include <assert.h> #include "buffer.h" #include "openssl_compat.h"
tests/unit_tests/openvpn/test_buffer.c +11 -11
@@ -463,38 +463,38 @@const char test1[] =A_TIMES_256 "EOL\n" A_TIMES_256 "EOF" ;/* line buffer bigger than actual line */ -assert_int_equal (buf_write (&buf, test1,sizeof (test1)), true); +assert_true (buf_write (&buf, test1,sizeof (test1))); status =buf_parse (&buf,'\n' , line,sizeof (line)); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,A_TIMES_256 "EOL" ); status =buf_parse (&buf,'\n' , line,sizeof (line)); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,A_TIMES_256 "EOF" );/* line buffer exactly same size as actual line + terminating \0 */ buf_reset_len (&buf); -assert_int_equal (buf_write (&buf, test1,sizeof (test1)), true); +assert_true (buf_write (&buf, test1,sizeof (test1))); status =buf_parse (&buf,'\n' , line,260 ); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,A_TIMES_256 "EOL" ); status =buf_parse (&buf,'\n' , line,260 ); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,A_TIMES_256 "EOF" );/* line buffer smaller than actual line */ buf_reset_len (&buf); -assert_int_equal (buf_write (&buf, test1,sizeof (test1)), true); +assert_true (buf_write (&buf, test1,sizeof (test1))); status =buf_parse (&buf,'\n' , line,257 ); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,A_TIMES_256 ); status =buf_parse (&buf,'\n' , line,257 ); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,"EOL" ); status =buf_parse (&buf,'\n' , line,257 ); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,A_TIMES_256 ); status =buf_parse (&buf,'\n' , line,257 ); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,"EOF" );gc_free (&gc);
tests/unit_tests/openvpn/test_cryptoapi.c +1 -1
@@ -121,7 +121,7 @@ { cert4, key4, cname4, "OVPN TEST CA2", "OVPN Test Cert 4", hash4, 0 }, { 0 } }; -assert (sizeof (certs_local) ==sizeof (certs)); +assert_int_equal (sizeof (certs_local),sizeof (certs));memcpy (certs, certs_local,sizeof (certs_local)); }
tests/unit_tests/openvpn/test_misc.c +1 -1
@@ -101,7 +101,7 @@const char *msg =parse_auth_failed_temp (&o, teststr);assert_string_equal (msg,"" );assert_int_equal (o.server_backoff_time,42 ); -assert_int_equal (o.no_advance, true); +assert_true (o.no_advance); } static void
tests/unit_tests/openvpn/test_pkcs11.c +1 -1
@@ -148,7 +148,7 @@ { cert4, key4, cname4, "OVPN TEST CA2", "OVPN Test Cert 4", { 0 }, NULL }, { 0 } }; -assert (sizeof (certs_local) ==sizeof (certs)); +assert_int_equal (sizeof (certs_local),sizeof (certs));memcpy (certs, certs_local,sizeof (certs_local)); }
[Openvpn-devel] [PATCH applied] Re: unit_tests: prefer proper cmocka assert helpers
Straightforward enough, and all cmoka tests still pass, on all platforms.
Your patch has been applied to the master branch.
commit c5e9950987b153ff572484bdf895b56c5dcc03dd
Author: Antonio Quartulli Date: Tue Nov 4 09:16:47 2025 +0100
unit_tests: prefer proper cmocka assert helpers
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1345
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg34179.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
cron2 has uploaded a new patch set (#2) to the change originally created by ordex. ( http://gerrit.openvpn.net/c/openvpn/+/1345?usp=email )
The following approvals got outdated and were removed:
Code-Review+2 by cron2
Change subject: unit_tests: prefer proper cmocka assert helpers
......................................................................
unit_tests: prefer proper cmocka assert helpers
We have agreed to never use the plain assert()
anywhere in the code.
Unit tests are almost there as they always use cmocka provided assert helpers, except for two cases. Convert those two to cmocka assert calls too.
While at it also ensure that the proper bool helpers are used rather than checking _int_equal against true/false.
Drop assert.h in cryptoapi.c as well as it's not needed anymore.
GitHub: Closes OpenVPN/openvpn#894
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1345
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg34179.html
---
M src/openvpn/cryptoapi.c
M tests/unit_tests/openvpn/test_buffer.c
M tests/unit_tests/openvpn/test_cryptoapi.c
M tests/unit_tests/openvpn/test_misc.c
M tests/unit_tests/openvpn/test_pkcs11.c
5 files changed, 14 insertions(+), 15 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/45/1345/2
src/openvpn/cryptoapi.c +0 -1
@@ -45,7 +45,6 @@#include <ncrypt.h> #include <stdio.h> #include <ctype.h> -#include <assert.h> #include "buffer.h" #include "openssl_compat.h"
tests/unit_tests/openvpn/test_buffer.c +11 -11
@@ -463,38 +463,38 @@const char test1[] =A_TIMES_256 "EOL\n" A_TIMES_256 "EOF" ;/* line buffer bigger than actual line */ -assert_int_equal (buf_write (&buf, test1,sizeof (test1)), true); +assert_true (buf_write (&buf, test1,sizeof (test1))); status =buf_parse (&buf,'\n' , line,sizeof (line)); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,A_TIMES_256 "EOL" ); status =buf_parse (&buf,'\n' , line,sizeof (line)); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,A_TIMES_256 "EOF" );/* line buffer exactly same size as actual line + terminating \0 */ buf_reset_len (&buf); -assert_int_equal (buf_write (&buf, test1,sizeof (test1)), true); +assert_true (buf_write (&buf, test1,sizeof (test1))); status =buf_parse (&buf,'\n' , line,260 ); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,A_TIMES_256 "EOL" ); status =buf_parse (&buf,'\n' , line,260 ); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,A_TIMES_256 "EOF" );/* line buffer smaller than actual line */ buf_reset_len (&buf); -assert_int_equal (buf_write (&buf, test1,sizeof (test1)), true); +assert_true (buf_write (&buf, test1,sizeof (test1))); status =buf_parse (&buf,'\n' , line,257 ); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,A_TIMES_256 ); status =buf_parse (&buf,'\n' , line,257 ); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,"EOL" ); status =buf_parse (&buf,'\n' , line,257 ); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,A_TIMES_256 ); status =buf_parse (&buf,'\n' , line,257 ); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,"EOF" );gc_free (&gc);
tests/unit_tests/openvpn/test_cryptoapi.c +1 -1
@@ -121,7 +121,7 @@ { cert4, key4, cname4, "OVPN TEST CA2", "OVPN Test Cert 4", hash4, 0 }, { 0 } }; -assert (sizeof (certs_local) ==sizeof (certs)); +assert_int_equal (sizeof (certs_local),sizeof (certs));memcpy (certs, certs_local,sizeof (certs_local)); }
tests/unit_tests/openvpn/test_misc.c +1 -1
@@ -101,7 +101,7 @@const char *msg =parse_auth_failed_temp (&o, teststr);assert_string_equal (msg,"" );assert_int_equal (o.server_backoff_time,42 ); -assert_int_equal (o.no_advance, true); +assert_true (o.no_advance); } static void
tests/unit_tests/openvpn/test_pkcs11.c +1 -1
@@ -148,7 +148,7 @@ { cert4, key4, cname4, "OVPN TEST CA2", "OVPN Test Cert 4", { 0 }, NULL }, { 0 } }; -assert (sizeof (certs_local) ==sizeof (certs)); +assert_int_equal (sizeof (certs_local),sizeof (certs));memcpy (certs, certs_local,sizeof (certs_local)); }
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1345?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I61e4968f2e83d12d4d3fc3ccba92a06eb5ed5866
Gerrit-Change-Number: 1345
Gerrit-PatchSet: 2
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1345?usp=email )
Change subject: unit_tests: prefer proper cmocka assert helpers
......................................................................
unit_tests: prefer proper cmocka assert helpers
We have agreed to never use the plain assert()
anywhere in the code.
Unit tests are almost there as they always use cmocka provided assert helpers, except for two cases. Convert those two to cmocka assert calls too.
While at it also ensure that the proper bool helpers are used rather than checking _int_equal against true/false.
Drop assert.h in cryptoapi.c as well as it's not needed anymore.
GitHub: Closes OpenVPN/openvpn#894
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1345
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg34179.html
---
M src/openvpn/cryptoapi.c
M tests/unit_tests/openvpn/test_buffer.c
M tests/unit_tests/openvpn/test_cryptoapi.c
M tests/unit_tests/openvpn/test_misc.c
M tests/unit_tests/openvpn/test_pkcs11.c
5 files changed, 14 insertions(+), 15 deletions(-)
src/openvpn/cryptoapi.c +0 -1
@@ -45,7 +45,6 @@#include <ncrypt.h> #include <stdio.h> #include <ctype.h> -#include <assert.h> #include "buffer.h" #include "openssl_compat.h"
tests/unit_tests/openvpn/test_buffer.c +11 -11
@@ -463,38 +463,38 @@const char test1[] =A_TIMES_256 "EOL\n" A_TIMES_256 "EOF" ;/* line buffer bigger than actual line */ -assert_int_equal (buf_write (&buf, test1,sizeof (test1)), true); +assert_true (buf_write (&buf, test1,sizeof (test1))); status =buf_parse (&buf,'\n' , line,sizeof (line)); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,A_TIMES_256 "EOL" ); status =buf_parse (&buf,'\n' , line,sizeof (line)); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,A_TIMES_256 "EOF" );/* line buffer exactly same size as actual line + terminating \0 */ buf_reset_len (&buf); -assert_int_equal (buf_write (&buf, test1,sizeof (test1)), true); +assert_true (buf_write (&buf, test1,sizeof (test1))); status =buf_parse (&buf,'\n' , line,260 ); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,A_TIMES_256 "EOL" ); status =buf_parse (&buf,'\n' , line,260 ); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,A_TIMES_256 "EOF" );/* line buffer smaller than actual line */ buf_reset_len (&buf); -assert_int_equal (buf_write (&buf, test1,sizeof (test1)), true); +assert_true (buf_write (&buf, test1,sizeof (test1))); status =buf_parse (&buf,'\n' , line,257 ); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,A_TIMES_256 ); status =buf_parse (&buf,'\n' , line,257 ); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,"EOL" ); status =buf_parse (&buf,'\n' , line,257 ); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,A_TIMES_256 ); status =buf_parse (&buf,'\n' , line,257 ); -assert_int_equal (status, true); +assert_true (status);assert_string_equal (line,"EOF" );gc_free (&gc);
tests/unit_tests/openvpn/test_cryptoapi.c +1 -1
@@ -121,7 +121,7 @@ { cert4, key4, cname4, "OVPN TEST CA2", "OVPN Test Cert 4", hash4, 0 }, { 0 } }; -assert (sizeof (certs_local) ==sizeof (certs)); +assert_int_equal (sizeof (certs_local),sizeof (certs));memcpy (certs, certs_local,sizeof (certs_local)); }
tests/unit_tests/openvpn/test_misc.c +1 -1
@@ -101,7 +101,7 @@const char *msg =parse_auth_failed_temp (&o, teststr);assert_string_equal (msg,"" );assert_int_equal (o.server_backoff_time,42 ); -assert_int_equal (o.no_advance, true); +assert_true (o.no_advance); } static void
tests/unit_tests/openvpn/test_pkcs11.c +1 -1
@@ -148,7 +148,7 @@ { cert4, key4, cname4, "OVPN TEST CA2", "OVPN Test Cert 4", { 0 }, NULL }, { 0 } }; -assert (sizeof (certs_local) ==sizeof (certs)); +assert_int_equal (sizeof (certs_local),sizeof (certs));memcpy (certs, certs_local,sizeof (certs_local)); }
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1345?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I61e4968f2e83d12d4d3fc3ccba92a06eb5ed5866
Gerrit-Change-Number: 1345
Gerrit-PatchSet: 2
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>